In this tangent story we will dive into detailed data on demand! We will look at a series of maps which shows accidents with a given degree of severity and contains the specific circumstances of that accident. This will give you all the information you need to judge what caused the accidents. Without further ado, let us dive into the first map!

In [1]:
from IPython.display import HTML

HTML('''<script>
code_show=true;
function code_toggle() {
if (code_show){
$('div.input').hide();
} else {
$('div.input').show();
}
code_show = !code_show
}
$( document ).ready(code_toggle);
</script>
The raw code for this IPython notebook is by default hidden for easier reading.
To toggle on/off the raw code, click <a href="javascript:code_toggle()">here</a>.''')
Out[1]:
The raw code for this IPython notebook is by default hidden for easier reading. To toggle on/off the raw code, click here.
In [2]:
# Install necessary packages
#!pip install geojson

# Imports
from IPython.display import display
from IPython.core.display import display, HTML
import folium
from folium.plugins import FastMarkerCluster
import tempfile
import plotly.express as px
import geojson
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
import plotly.express as px
sns.set_style('darkgrid')
%matplotlib inline
In [3]:
# Load data 
df = pd.read_csv('cleaned_data.csv')
df['date'] = pd.to_datetime(df.date) 
In [4]:
lat_lon = df[df.severity_name == 'Killed'][['longS','latS','severity','date_full','severity_name','gender_name','age','lum_name',
'atm_name','roadtype','traffic lanes','surface condition','crude_vc','collision_type',
'User category','trip purpose','safety','prof','plan']].sample(10000)
locations = lat_lon[['latS','longS']]
locationlist = locations.values.tolist()

Below a map over fatal accidents can be seen. Remember to click on the points to get characteristics over the accident, victim and surroundings!

In [5]:
# Possible styles for folium, last do not work properly
t_list = ["Stamen Terrain", "Stamen Toner", "Mapbox Bright", 'Cartodb Positron']

# Define the map with coordinates, style and zoom
m = folium.Map(location=[47.092038, 2.392312], 
                    tiles = t_list[3],
                    zoom_start = 6)

# Define colours
colours = ['lightgreen','black','darkred','orange']
# Unscathed, killed, hospitalized, light injury

# Add markers for each accident
for point in range(0, len(locationlist[:4000])):
    html = '''
    Accident characteristics:<br>
    Date: {}<br>
    Severity: {}<br><br>
    Victim characteristics:<br>
    Age: {}<br>
    Gender: {}<br>
    Trip purpose: {}<br>
    Vehicle type: {}<br>
    User status: {}<br>
    Collision type: {}<br>
    Safety: {}<br><br>
    Environment characteristics:<br>
    Roadtype: {}<br>
    Surface conditions: {}<br>
    Lumination: {}<br>
    Atmosphere: {}<br>
    Vertical profile of road: {}<br>
    Horizontal profile of road: {}<br>
    Traffic lanes: {}
    '''.format(lat_lon.date_full.iloc[point],
    lat_lon.severity_name.iloc[point],
    lat_lon.age.iloc[point],
    lat_lon.gender_name.iloc[point],
    lat_lon['trip purpose'].iloc[point],
    lat_lon.crude_vc.iloc[point],
    lat_lon['User category'].iloc[point],
    lat_lon.collision_type.iloc[point],
    lat_lon.safety.iloc[point],
    lat_lon.roadtype.iloc[point],
    lat_lon['surface condition'].iloc[point],
    lat_lon.lum_name.iloc[point],
    lat_lon.atm_name.iloc[point],
    lat_lon.prof.iloc[point],
    lat_lon.plan.iloc[point],
    lat_lon['traffic lanes'].iloc[point])
    #lat_lon.infrastructure.iloc[point])
    iframe = folium.IFrame(html,width=400,height=300)
    popup = folium.Popup(iframe,max_width=500)
    folium.CircleMarker(locationlist[point], radius=2, popup=popup, color=colours[lat_lon['severity'].iloc[point]-1]).add_to(m)

# Add clusters of number of accidents in areas
#m.add_child(FastMarkerCluster(locations[['latS', 'longS']].values.tolist()))

# Display map
m
Out[5]:
Make this Notebook Trusted to load map: File -> Trust Notebook

The map above show that everyone are at risk of being involved in a serious accident involving at least one vehicle (even at sea apparently). To better understand these accidents take a look at the different points, traverse France by hovering between departments and zoom into the data you want to explore.

In [6]:
lat_lon = df[df.severity_name == 'Hospitalized wounded'][['longS','latS','severity','date_full','severity_name','gender_name','age','lum_name',
'atm_name','roadtype','traffic lanes','surface condition','crude_vc','collision_type',
'User category','trip purpose','safety','prof','plan']].sample(10000)
locations = lat_lon[['latS','longS']]
locationlist = locations.values.tolist()

Below a map over severe accidents leading to hospitalization can be seen.

In [7]:
# Possible styles for folium, last do not work properly
t_list = ["Stamen Terrain", "Stamen Toner", "Mapbox Bright", 'Cartodb Positron']

# Define the map with coordinates, style and zoom
m = folium.Map(location=[47.092038, 2.392312], 
                    tiles = t_list[3],
                    zoom_start = 6)

# Define colours
colours = ['lightgreen','black','darkred','orange']
# Unscathed, killed, hospitalized, light injury

# Add markers for each accident
for point in range(0, len(locationlist[:4000])):
    html = '''
    Accident characteristics:<br>
    Date: {}<br>
    Severity: {}<br><br>
    Victim characteristics:<br>
    Age: {}<br>
    Gender: {}<br>
    Trip purpose: {}<br>
    Vehicle type: {}<br>
    User status: {}<br>
    Collision type: {}<br>
    Safety: {}<br><br>
    Environment characteristics:<br>
    Roadtype: {}<br>
    Surface conditions: {}<br>
    Lumination: {}<br>
    Atmosphere: {}<br>
    Vertical profile of road: {}<br>
    Horizontal profile of road: {}<br>
    Traffic lanes: {}
    '''.format(lat_lon.date_full.iloc[point],
    lat_lon.severity_name.iloc[point],
    lat_lon.age.iloc[point],
    lat_lon.gender_name.iloc[point],
    lat_lon['trip purpose'].iloc[point],
    lat_lon.crude_vc.iloc[point],
    lat_lon['User category'].iloc[point],
    lat_lon.collision_type.iloc[point],
    lat_lon.safety.iloc[point],
    lat_lon.roadtype.iloc[point],
    lat_lon['surface condition'].iloc[point],
    lat_lon.lum_name.iloc[point],
    lat_lon.atm_name.iloc[point],
    lat_lon.prof.iloc[point],
    lat_lon.plan.iloc[point],
    lat_lon['traffic lanes'].iloc[point])
    #lat_lon.infrastructure.iloc[point])
    iframe = folium.IFrame(html,width=400,height=300)
    popup = folium.Popup(iframe,max_width=500)
    folium.CircleMarker(locationlist[point], radius=2, popup=popup, color=colours[lat_lon['severity'].iloc[point]-1]).add_to(m)

# Add clusters of number of accidents in areas
#m.add_child(FastMarkerCluster(locations[['latS', 'longS']].values.tolist()))

# Display map
m
Out[7]:
Make this Notebook Trusted to load map: File -> Trust Notebook

The geographical story over these severe accidents are very similar to that of the fatal accidents; they seem to hit everyone and are not dependent on your location as much. Try to see if you can find other trends!

In [8]:
lat_lon = df[df.severity_name == 'Light injury'][['longS','latS','severity','date_full','severity_name','gender_name','age','lum_name',
'atm_name','roadtype','traffic lanes','surface condition','crude_vc','collision_type',
'User category','trip purpose','safety','prof','plan']].sample(10000)
locations = lat_lon[['latS','longS']]
locationlist = locations.values.tolist()

Below a map over light accidents with minor injuries can be seen.

In [9]:
# Possible styles for folium, last do not work properly
t_list = ["Stamen Terrain", "Stamen Toner", "Mapbox Bright", 'Cartodb Positron']

# Define the map with coordinates, style and zoom
m = folium.Map(location=[47.092038, 2.392312], 
                    tiles = t_list[3],
                    zoom_start = 6)

# Define colours
colours = ['lightgreen','black','darkred','orange']
# Unscathed, killed, hospitalized, light injury

# Add markers for each accident
for point in range(0, len(locationlist[:4000])):
    html = '''
    Accident characteristics:<br>
    Date: {}<br>
    Severity: {}<br><br>
    Victim characteristics:<br>
    Age: {}<br>
    Gender: {}<br>
    Trip purpose: {}<br>
    Vehicle type: {}<br>
    User status: {}<br>
    Collision type: {}<br>
    Safety: {}<br><br>
    Environment characteristics:<br>
    Roadtype: {}<br>
    Surface conditions: {}<br>
    Lumination: {}<br>
    Atmosphere: {}<br>
    Vertical profile of road: {}<br>
    Horizontal profile of road: {}<br>
    Traffic lanes: {}
    '''.format(lat_lon.date_full.iloc[point],
    lat_lon.severity_name.iloc[point],
    lat_lon.age.iloc[point],
    lat_lon.gender_name.iloc[point],
    lat_lon['trip purpose'].iloc[point],
    lat_lon.crude_vc.iloc[point],
    lat_lon['User category'].iloc[point],
    lat_lon.collision_type.iloc[point],
    lat_lon.safety.iloc[point],
    lat_lon.roadtype.iloc[point],
    lat_lon['surface condition'].iloc[point],
    lat_lon.lum_name.iloc[point],
    lat_lon.atm_name.iloc[point],
    lat_lon.prof.iloc[point],
    lat_lon.plan.iloc[point],
    lat_lon['traffic lanes'].iloc[point])
    #lat_lon.infrastructure.iloc[point])
    iframe = folium.IFrame(html,width=400,height=300)
    popup = folium.Popup(iframe,max_width=500)
    folium.CircleMarker(locationlist[point], radius=2, popup=popup, color=colours[lat_lon['severity'].iloc[point]-1]).add_to(m)

# Add clusters of number of accidents in areas
#m.add_child(FastMarkerCluster(locations[['latS', 'longS']].values.tolist()))

# Display map
m
Out[9]:
Make this Notebook Trusted to load map: File -> Trust Notebook

As there are the same number of points in all maps presented it shows light injuries seems to strike in the cities more often as the general land of France seems rather sparse or unpopulated by the accident markers. Can you see any recurring differences in the accident information above compared to the more serious accidents?

In [10]:
lat_lon = df[df.severity_name == 'Unscathed '][['longS','latS','severity','date_full','severity_name','gender_name','age','lum_name',
'atm_name','roadtype','traffic lanes','surface condition','crude_vc','collision_type',
'User category','trip purpose','safety','prof','plan']].sample(10000)
locations = lat_lon[['latS','longS']]
locationlist = locations.values.tolist()

Below a map over mild accidents without injury can be seen.

In [11]:
# Possible styles for folium, last do not work properly
t_list = ["Stamen Terrain", "Stamen Toner", "Mapbox Bright", 'Cartodb Positron']

# Define the map with coordinates, style and zoom
m = folium.Map(location=[47.092038, 2.392312], 
                    tiles = t_list[3],
                    zoom_start = 6)

# Define colours
colours = ['lightgreen','black','darkred','orange']
# Unscathed, killed, hospitalized, light injury

# Add markers for each accident
for point in range(0, len(locationlist[:4000])):
    html = '''
    Accident characteristics:<br>
    Date: {}<br>
    Severity: {}<br><br>
    Victim characteristics:<br>
    Age: {}<br>
    Gender: {}<br>
    Trip purpose: {}<br>
    Vehicle type: {}<br>
    User status: {}<br>
    Collision type: {}<br>
    Safety: {}<br><br>
    Environment characteristics:<br>
    Roadtype: {}<br>
    Surface conditions: {}<br>
    Lumination: {}<br>
    Atmosphere: {}<br>
    Vertical profile of road: {}<br>
    Horizontal profile of road: {}<br>
    Traffic lanes: {}
    '''.format(lat_lon.date_full.iloc[point],
    lat_lon.severity_name.iloc[point],
    lat_lon.age.iloc[point],
    lat_lon.gender_name.iloc[point],
    lat_lon['trip purpose'].iloc[point],
    lat_lon.crude_vc.iloc[point],
    lat_lon['User category'].iloc[point],
    lat_lon.collision_type.iloc[point],
    lat_lon.safety.iloc[point],
    lat_lon.roadtype.iloc[point],
    lat_lon['surface condition'].iloc[point],
    lat_lon.lum_name.iloc[point],
    lat_lon.atm_name.iloc[point],
    lat_lon.prof.iloc[point],
    lat_lon.plan.iloc[point],
    lat_lon['traffic lanes'].iloc[point])
    #lat_lon.infrastructure.iloc[point])
    iframe = folium.IFrame(html,width=400,height=300)
    popup = folium.Popup(iframe,max_width=500)
    folium.CircleMarker(locationlist[point], radius=2, popup=popup, color=colours[lat_lon['severity'].iloc[point]-1]).add_to(m)

# Add clusters of number of accidents in areas
#m.add_child(FastMarkerCluster(locations[['latS', 'longS']].values.tolist()))

# Display map
m
Out[11]:
Make this Notebook Trusted to load map: File -> Trust Notebook

It seems mild injuries are also centered in major towns. Does the accident information seem similar to that of the light injuries?